package com.example.mvvmhttpdemo.viewmodel.request.state

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.example.mvvmhttpdemo.data.model.bean.BannerResponse
import com.example.mvvmhttpdemo.data.model.bean.SearchResponse
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.demo.app.network.apiService
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

class MainViewModel : BaseViewModel() {
    //首页轮播图数据
    var bannerData: MutableLiveData<ResultState<ArrayList<BannerResponse>>> = MutableLiveData()
    var hotData: MutableLiveData<ArrayList<SearchResponse>> = MutableLiveData()

    /**
     * 请求Banner 返回数据
     */
    fun getBannerData() {
        request({ apiService.getBanner()}, bannerData)
    }

    /**
     * 请求热词 返回数据
     */
    fun getHotData(){
        request({ apiService.getSearchData() }, {
            val name = it[0].name
            val order = it[0].order
            Log.d("LUO","---请求热词返回数据：${it.toString()}")
            Log.d("LUO","--name：${name}----order:${order}")
            hotData.value = it
        },{
            Log.d("LUO","---请求热词报错：${it.message}")
        },true)
    }
}